package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.LuntaiRescueApplicationDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LuntaiRescueApplication;
import com.ruoyi.system.service.ILuntaiRescueApplicationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户救援申请Controller
 *
 * @author ruoyi
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/system/application")
public class LuntaiRescueApplicationController extends BaseController {
    @Autowired
    private ILuntaiRescueApplicationService luntaiRescueApplicationService;

    /**
     * 查询用户救援申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:application:list')")
    @GetMapping("/list")
    public TableDataInfo list(LuntaiRescueApplication luntaiRescueApplication) {
        startPage();
        List<LuntaiRescueApplication> list = luntaiRescueApplicationService.selectLuntaiRescueApplicationList(luntaiRescueApplication);
        return getDataTable(list);
    }

    /**
     * 查询用户救援申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:application:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(LuntaiRescueApplicationDto luntaiRescueApplication) {
        startPage();
        List<LuntaiRescueApplicationDto> list = luntaiRescueApplicationService.selectLuntaiRescueApplicationList2(luntaiRescueApplication);
        return getDataTable(list);
    }

    /**
     * 导出用户救援申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:application:export')")
    @Log(title = "用户救援申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LuntaiRescueApplication luntaiRescueApplication) {
        List<LuntaiRescueApplication> list = luntaiRescueApplicationService.selectLuntaiRescueApplicationList(luntaiRescueApplication);
        ExcelUtil<LuntaiRescueApplication> util = new ExcelUtil<LuntaiRescueApplication>(LuntaiRescueApplication.class);
        util.exportExcel(response, list, "用户救援申请数据");
    }

    /**
     * 获取用户救援申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:application:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(luntaiRescueApplicationService.selectLuntaiRescueApplicationById(id));
    }

    /**
     * 新增用户救援申请
     */
    @PreAuthorize("@ss.hasPermi('system:application:add')")
    @Log(title = "用户救援申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LuntaiRescueApplication luntaiRescueApplication) {
        return toAjax(luntaiRescueApplicationService.insertLuntaiRescueApplication(luntaiRescueApplication));
    }

    /**
     * 修改用户救援申请
     */
    @PreAuthorize("@ss.hasPermi('system:application:edit')")
    @Log(title = "用户救援申请", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody LuntaiRescueApplication luntaiRescueApplication) {
        return toAjax(luntaiRescueApplicationService.updateLuntaiRescueApplication(luntaiRescueApplication));
    }

    /**
     * 删除用户救援申请
     */
    @PreAuthorize("@ss.hasPermi('system:application:remove')")
    @Log(title = "用户救援申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(luntaiRescueApplicationService.deleteLuntaiRescueApplicationByIds(ids));
    }
}
